package com.sc.ktapplication.common.util

import android.content.Context
import android.os.Environment
import java.io.File

object MediaUtil {

    const val PICTURE_DIR = "picture"
    const val VIDEO_DIR = "video"
    const val VOICE_DIR = "audio"

    /**
     * APP的目录
     * @param context
     * @return
     */
    fun getAppFolder(context: Context): String {
        var path: String? = null
        path = if (Environment.getExternalStorageState() == Environment.MEDIA_MOUNTED) {
            Environment.getExternalStorageDirectory().toString() + "/bsf/"
        } else {
            context.applicationContext.filesDir.absolutePath + "/bsf/"
        }
        val file = File(path)
        if (!file.exists()) {
            file.mkdir()
        }
        return path
    }

    /**
     * APP存放打印文件的目录
     * @param context
     * @return
     */
    fun getAppPDFFolder(context: Context): String {
        var path: String? = null
        path = if (Environment.getExternalStorageState() == Environment.MEDIA_MOUNTED) {
            Environment.getExternalStorageDirectory().toString() + "/bsf/pdf/"
        } else {
            context.applicationContext.filesDir.absolutePath + "/bsf/pdf/"
        }
        val file = File(path)
        if (!file.exists()) {
            file.mkdir()
        }
        return path
    }

    /**
     * 获取download目录
     * @param context
     * @return
     */
    fun getDownloadFolder(context: Context): String {
        var path: String? = null
        path = if (Environment.getExternalStorageState() == Environment.MEDIA_MOUNTED) {
            Environment.getExternalStorageDirectory().toString() + "/Downloads/"
        } else {
            context.applicationContext.filesDir.absolutePath + "/Downloads/"
        }
        val file = File(path)
        if (!file.exists()) {
            file.mkdir()
        }
        return path
    }

    /**
     * sd卡是否挂载
     * @return
     */
    val isSdCardMounted: Boolean
        get() = Environment.getExternalStorageState() == Environment.MEDIA_MOUNTED
}